package com.lxw.mq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class ConfigMq {

    private Map<String, Object> args = new HashMap<>();

    private static final String EXCHANGE_NAME = "ex_routing_cms_postpage";
    @Value("${fhs.mq.queue}")
    private String QUEUE_NAME;
    @Value("${fhs.mq.routingKey}")
    private String ROUTING_NAME;
    //声明队列
    @Bean
    public Queue queue(){
        return new Queue(QUEUE_NAME,true, false, false, args);
    }
    //声明交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(EXCHANGE_NAME);
    }
    //绑定交换机

    @Bean
    public Binding binding(DirectExchange directExchange,Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with(ROUTING_NAME);

    }


}
